import 'package:flutter/material.dart';
import 'package:ton_demo/calendar/utils/enums.dart';
import 'package:ton_demo/calendar/utils/extensions.dart';

class TitleWidget extends StatelessWidget {
  final DateTime month;
  final String locale;
  final TextStyle? textStyle;
  final TextAlign? textAlign;
  final ViewType type;
  final Widget Function(BuildContext context, String month)? monthBuilder;

  const TitleWidget({
    super.key,
    required this.month,
    required this.locale,
    required this.monthBuilder,
    required this.textStyle,
    required this.textAlign,
    required this.type,
  });

  @override
  Widget build(BuildContext context) {
    final text = type == ViewType.YEAR
        ? ''
        : type == ViewType.MONTH
            ? '${month.year}年'
            : '${month.year}年${month.month}月';
    if (monthBuilder != null) {
      return monthBuilder!(context, text);
    }

    return _beauty(context, text);
  }

  Widget _beauty(BuildContext context, String text) {
    return Text(
      text.capitalize(),
      textAlign: textAlign ?? TextAlign.center,
      style: textStyle ?? Theme.of(context).textTheme.titleLarge!,
    );
  }
}
